---
--类名: ChallengeListView.lua
--创建日期: 2018-9-11
--创建人: 宋建邦
--功能描述:挑战权列表视图
--修改内容:
--修改日期:
--修改人:
--修改备注:

local ChallengeListView = class("ChallengeListView", app.mvc.ViewBase)
ChallengeListView.VIEW_ROOT_RES = Res.ResultTipsView

function ChallengeListView:init()
    self:setBackGroundColorType(0)
    self:setNodeEventEnabled(true)

    self.lblTlt = self._root:findChild("Panel/tlt")
    self.lblTlt:setString(L("lua_code_text_509"))
    self.lblTltDesc = self._root:findChild("Panel/tlt_name")

    self.btnClose = self._root:findChild("Panel/Button_close")
    self.btnClose:addClickEventListener(function(sender)
        local bc = app:getInst("BiddingController")
        bc:closeChellengeListView()
    end)
    self.lblClose = self._root:findChild("Panel/Button_close/name")
    self.lblClose:setString(L("lua_code_text_59"))

    self.mapNodes = {}
    for i = 1, 5 do
        table.insert(self.mapNodes, self:newMapNodeRender(self._root:findChild("Panel/map_"..tostring(i))))
    end
end

function ChallengeListView:newMapNodeRender(n)
    local mm = app:getInst("WorldMapModel")
    n.init = function(self)
        self.mapIcon = self:findChild("Panel/Panel_icon/map")
        self.mapName = self:findChild("Panel/tlt")
        self.lblNumb = self:findChild("Panel/num")
    end

    n.refresh = function(self, data)
        local tc = mm._zoneDict[data.townId]

        self.mapName:setString(tc:getName())
        self.mapIcon:loadTexture(tc:getIcon())
        self.lblNumb:setString(string.format(L("lua_code_text_183"), data.prosperity, tc.blessExpMax))
    end
    n:init()
    return n
end

function ChallengeListView:onExit()
end

function ChallengeListView:refresh(data)
    for i = 1, 5 do
        if data[i] then
            self.mapNodes[i]:show()
            self.mapNodes[i]:refresh(data[i])
        else
            self.mapNodes[i]:hide()
        end
    end
    self:refreshStatusString(data[1])
end

function ChallengeListView:refreshStatusString(d)
    if d then
        local bc = app:getInst("BiddingController")
        local ti = bc.battleMapModel.hTownInfos[d.townId]
        local s = protobuf.enum_id("pb_town.PHASE", ti.data.phase)
        if s == 2 then
            self.lblTlt:setString(L("bidding_chellenge_title_ready"))
            self.lblTltDesc:setString(L("bidding_chellenge_desc_ready"))
        else
            self.lblTlt:setString(L("bidding_chellenge_title_fight"))
            self.lblTltDesc:setString(L("bidding_chellenge_desc_fight"))
        end
    end
end

return ChallengeListView